from BeautifulSoup import BeautifulSoup
import re
import urllib2



def getGamesInfo( soup ):
    #search for all game entries
    gdlist = soup('div',{'class':'callout_listing'})
    res = []
    for gd in gdlist:
        #name
        name = gd.findAll('a',{'class':'play_link'})[0].text
        #plays
        tmp = gd.findAll(text=re.compile('plays'))[0]
        plays = re.sub("[^0-9]*","",tmp)

        #img link
        img = gd.findAll('img')[0]['src']

        #developer
        dvlp = gd.findAll('a',{'class':'developer_icon spritesite'})[0].text

        #when published
        when = gd.findAll('dd',{'class':'summary'})[0].findAll('em')[0].text

        #description
        summary = gd.findAll('dd',{'class':'summary'})[0].text
        res.append((name,plays,img,dvlp,when,summary,))
    return res

def saveToTmp( url ):
    r = urllib2.urlopen( url )
    return r.read()

if __name__ == "__main__":
    soup = BeautifulSoup( loadUrl('http://www.kongregate.com/strategy-defense-games'))
    print soup.findAll('div')


